using System;
using System.Collections;
using System.Collections.Generic;
using SUIFW;
using TMPro;
using UnityEngine;
using UnityEngine.UI;

public class GovernancePanel : BaseUIForm
{
    [SerializeField] private TextMeshProUGUI _totalMilitaryStrength;
    [SerializeField] private TextMeshProUGUI _reserveTroops;
    [SerializeField] private List<GameObject> insideParts = new List<GameObject>();
    private void Awake()
    {
        base.CurrentUIType.UIForms_Type = UIFormType.Normal;
        base.CurrentUIType.UIForms_ShowMode = UIFormShowMode.Normal;
        base.CurrentUIType.UIForms_LucencyType = UIFormLucencyType.Lucency;
        
        RegisterButtonObjectEvent("Button-Military", p =>
        {
            OpenUIForm("MilitaryPanel");
            CloseUIForm();
        });
        
        
        
        RegisterButtonObjectEvent("Button-Government",p=>
        {
            OpenUIForm("CanvasStatic");
            ChangeInsidePart("Government");
        });
        
        RegisterButtonObjectEvent("Button-Merchants",p=>
        {
            ChangeInsidePart("Merchant");
            CloseUIForm("CanvasStatic"); 
        });
        
        RegisterButtonObjectEvent("Button-Trade",p=>
        {
            ChangeInsidePart("Trade");
            CloseUIForm("CanvasStatic"); 
        });
        
        RegisterButtonObjectEvent("Button-Taxes",p=>
        {
            ChangeInsidePart("Taxation");
            CloseUIForm("CanvasStatic"); 
        });
        
        
        RegisterButtonObjectEvent("Quit",g =>
        {
            CloseUIForm("CanvasStatic");
            CloseUIForm();
            OpenUIForm("CanvasMain");
            
        });
    }

    private void Start()
    {
        Refresh();
        EventCenter.AddEventListener("Governance_Refresh", Refresh);
    }

    private void Refresh()
    {
        _totalMilitaryStrength.text = GameManager.Instance.GetTotalMilitaryStrength().ToString();
        _reserveTroops.text = GameManager.Instance.GetReserveTroops() + "/" +
                              GameManager.Instance.GetReserveTroopsMax();
    }

    private void ChangeInsidePart(string nowPart)
    {
        foreach (var t in insideParts)
        {
            t.SetActive(t.name == nowPart);
        }
    }
    
}
